package com.wemei.auto.ui.widget.jsbridge;

import android.webkit.WebView;

import com.wemei.auto.ui.utils.Logger;

import java.lang.ref.WeakReference;


/**
 * @author Administrator on 2017/3/1 0001.
 */

public class JsCallback {
    private String apiCb;
    private WeakReference<WebView> webViewWeakReference;

    public JsCallback(String apiCb, WebView webView) {
        this.apiCb = apiCb;
        this.webViewWeakReference = new WeakReference<>(webView);
    }

    public void call(String param) {
        WebView webView = webViewWeakReference.get();
        if (webView != null) {
            final String js = "javascript:window['" + apiCb + "']('" + param + "')";
            Logger.e(js);
            webView.post(() -> webViewWeakReference.get().loadUrl(js));
        }
    }
}
